/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


package hessingerbg.gui;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.StyledDocument;

/**
 *
 * @author MikeLaptop
 */
public class Version {

    /**
     * Version control String
     * Client Version = A.BC
     * Release Version = a.bc
     * Versions are out of date if and only if (A < a) | )B < b) | (C < c)
     * Any letters or numbers preceding A.AA are for minor updates and do not
     * force a client update.
     */
    public static final String version = "1.01";

    @Deprecated
    /**
     * As of patch 1.01 getPatchnotes() should be called instead.
     */
    public static final String patchnotes = "";


    public static String getPatchnotes() throws FileNotFoundException, MalformedURLException, IOException
    {
        URL url = new URL("http://hessbg.co.cc/patchnotes.txt");
        URLConnection urlConn = url.openConnection();
        urlConn.setDoInput(true);
        urlConn.setUseCaches(false);
        BufferedReader dis = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));


        String note = "";
        String line = "PATCH NOTES \n =========================================";

        while(line != null)
        {
            note = note + line + "\n";
            line = dis.readLine();
        }

        return note;
    }

    public static boolean isUpdateToDate() throws FileNotFoundException, MalformedURLException, IOException
    {

        URL url = new URL("http://hessbg.co.cc/version.txt");
        URLConnection urlConn = url.openConnection();
        urlConn.setDoInput(true);
        urlConn.setUseCaches(false);
        BufferedReader dis = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
        String ver = dis.readLine();
        boolean ret = true;

        for(int i = 0; i < version.length(); i++)
        {
            if(ver.substring(i, i+1).compareTo(version.substring(i, i+1)) > 0)
                ret = false;
        }
        
        return ret;
    }

    public static String getDownloadLink() throws FileNotFoundException, MalformedURLException, IOException
    {
        URL url = new URL("http://hessbg.co.cc/download.txt");
        URLConnection urlConn = url.openConnection();
        urlConn.setDoInput(true);
        urlConn.setUseCaches(false);
        BufferedReader dis = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));

        return dis.readLine();
    }
}
